package com.un.ebs.product.controller;

import com.un.ebs.core.util.WebResult;
import com.un.ebs.core.util.WebUtils;
import com.un.ebs.product.dto.ProductClassTimeAddDto;
import com.un.ebs.product.dto.ProductClassTimeUpdateDto;
import com.un.ebs.product.dto.ProductClassTimeVo;
import com.un.ebs.product.service.ProductClassTimeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liubo
 * @email liubocs@163.com
 * @date 2020/5/7 16:09
 */
@RestController
@RequestMapping("/productClassTime")
@Api(value = "product-class-time", description = "品类服务时段")
public class ProductClassTimeController {

    @Autowired
    private ProductClassTimeService service;

    @PostMapping("add")
    @ApiOperation("添加")
    public WebResult add(@RequestBody @Validated ProductClassTimeAddDto req) {
        service.add(req);
        return WebUtils.success();
    }

    @PostMapping("update")
    @ApiOperation("更新")
    public WebResult update(@RequestBody @Validated ProductClassTimeUpdateDto req) {
        service.udpate(req);
        return WebUtils.success();
    }

    @DeleteMapping("delete")
    @ApiOperation("删除")
    public WebResult delete(@RequestParam String id) {
        service.delete(id);
        return WebUtils.success();
    }

    @GetMapping("list")
    @ApiOperation("查询")
    public WebResult<List<ProductClassTimeVo>> query(@RequestParam String classId) {
        return WebUtils.success(service.query(classId));
    }
}
